LK

Modular 3D Dungeon-Generator

Finished
GitHub

The generator begins by initializing a configurable three-dimensional grid, where each cell is represented by a grid actor.

Within this grid, rooms of variable size and rotation are randomly placed.

To ensure vertical connectivity, staircases are added whenever separate floors are not directly connected, guaranteeing traversal along the Z-axis.

Once the spatial layout of rooms and staircases is established, the system evaluates each room’s door positions and determines a center of mass for every occupied floor level. These centers act as vertices for subsequent graph calculations. The door positions determine the possible starting and ending points for the algorithm used later to connect the rooms.

Using the collection of centers, a Delaunay triangulation is generated to create an initial connectivity graph that logically links all rooms seperately for each floor.

From this triangulated graph, the generator derives a Minimal Spanning Tree via Prim’s algorithm, ensuring that every room is accessible from any other while maintaining minimal path redundancy. To introduce variation, a subset of additional connections from the triangulation can be randomly reintroduced, forming occasional loops.

With the connectivity graph defined, the generator employs a grid-based A* pathfinding implementation to create actual passages between rooms. Each route is constructed through the door positions on a per-floor basis until all rooms are connected.

To better illustrate how the graph algorithms operate, here is an example of a generated dungeon with a height of 1.

For those interested in the project’s code, the GitHub repository can be found below the video. Please note that this was one of my first projects, so the structure may be a bit harder to follow and less polished.